import sys
goods = {'F00001':{'name':'苹果','price':1.2},'F00002':{'name':'香蕉','price':5.5}}
user = ["liao",{"liao":'123',"money":100},"wu",{"wu":'123',"money":100}]
shop1 = {'F00001':0,'F00002':0}
def main():
    while 1:
        a = input("欢迎使用三乐购物系统,输入1登录，输入2注册，exit退出:")
        if a == "1":
            login()
        elif a == "2":
            register()
        elif a == "exit":
            sys.exit(0)
        else:
            print("输入不合法")
def login():
    user1 = input("请输入账号：")
    a = 0
    for i in user:
        if i == user1:
            pwd = input("请输入密码：")
            global n
            n = user.index(user1)+1
            a = 1
            if pwd == user[n][user1]:
                shop()
                break
            elif pwd == 'exit':
                main()
            else:
                print("密码错误,请重新输入")
                main()
    if a == 0:
        print("账号错误,请重新输入")


def shop():
    print("商品：")
    print(goods)
    while 1:
        num1 = input("输入商品编号可以加入购物车，输入1结算:")
        global money1
        money1 = 0
        for i in goods:
            if num1 == '1':
                pyment()
                return 1
            elif num1 == "exit":
                print(user[n])
                return 1
            elif num1 == i:
                num2 = input("请输入要购买数量：")
                shop1[num1] = int(num2)
                money1 =+ shop1[num1]*goods[num1]['price']

def pyment():
    if money1 > user[n]['money']:
        print("余额不足")
    else:
        user[n]["money"] = user[n]["money"] - money1
        print("购买成功")
    num2 = input("输入exit退出:")
    if  num2 == "exit":
        print("你购买了苹果 {F00001} 个,香蕉 {F00002} 个".format(**shop1))
        print("余额为：",user[n]['money'])
        print("退出成功")
        main()
    else:
        print("输入不合法")

def register():
    while 1:
        name1 = input("请输入注册账号：")
        if name1 == 'exit':
            break
        else:
            c = 0
            for i in user:
                if name1 == i:
                    print("该用户已被注册")
                    c = 1
            if c == 0:
                pwd2 = input("请输入密码：")
                if pwd2 == 'exit':
                    main()
                else:
                    user.append(name1)
                    user.append({name1:pwd2,"money":100})
                    print("注册成功")
                    main()

main()